<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/design/template.xhtml">
  <ui:define name="body">

  <h:form id="frmListOrders" prependId="false">
    <p:panel id="pnlListOrders" header="Lista pedidos">

      <p:spacer height="10" />
      <p:messages for="frmListOrders"/>
      <!-- 
      <p:panel id="pnlFilterOrder">
      <f:facet name="header">Filtro lista pedidos</f:facet>
      <h:panelGrid columns="8" >
        <h:outputText value="Pedido:" />
        <h:selectOneMenu id="orderStatusFilter" value="#{orderAction.orderFilter.orderStatus.id}" style="width:150px;" >  
          <f:selectItem itemValue="0" itemLabel="Todas situações"/>  
          <f:selectItems value="#{orderAction.orderStatusItems}"/>  
          <p:ajax update="tblOrders" listener="{orderAction.clearOrders}" />                     
        </h:selectOneMenu>
        <p:spacer width="5" />
        <h:outputText value="Pagamento:" />
        <h:selectOneMenu id="paymentStatusFilter" value="#{orderAction.orderFilter.paymentStatus.id}" style="width:150px;" >  
          <f:selectItem itemValue="0" itemLabel="Todas situações"/>  
          <f:selectItems value="#{orderAction.paymentStatusItems}"/>  
          <p:ajax update="tblOrders" listener="{orderAction.clearOrders}" />                     
        </h:selectOneMenu>
        <p:spacer width="5" />
        <h:outputText value="Venda:" />
        <h:selectOneMenu id="sellStatusFilter" value="#{orderAction.orderFilter.sellStatus.id}" style="width:150px;" >  
          <f:selectItem itemValue="0" itemLabel="Todas situações"/>  
          <f:selectItems value="#{orderAction.sellStatusItems}"/>  
          <p:ajax update="tblOrders" listener="{orderAction.clearOrders}" />                     
        </h:selectOneMenu>
      </h:panelGrid>
      </p:panel>
      <p:spacer height="20" />
       -->

      <h:panelGrid columns="8" >
        <h:outputText value="Filtro:" />
        <h:panelGroup>
          <h:selectBooleanCheckbox id="currencyType" value="#{orderAction.pendentOrders}"></h:selectBooleanCheckbox><h:outputText value="Pedidos pendentes" />
        </h:panelGroup>
        <p:commandButton action="#{orderAction.clearOrders}" value="filtrar" update="tblOrders" ajax="true" />
      </h:panelGrid>

      <p:dataTable id="tblOrders" value="#{orderAction.orders}" var="order" style="width:100%;" columnsWidth="11%,26%,15%,10%,10%,10%,4%,14%"
                   selection="#{orderAction.selectedOrder}" selectionMode="single"
                   rowSelectListener="#{orderAction.onRowSelect}" onRowSelectUpdate="pnlDetailOrder" onRowSelectComplete="pnlDetailOrder.show()" >  

        <p:column style="text-align:center;">
          <f:facet name="header">
            <h:outputText value="Data" />
          </f:facet>
          <h:outputText value="#{order.orderDate}" style="#{order.paymentDate eq null ? 'color: red;' : ''}" >
            <f:convertDateTime pattern="dd/MM/yyyy" />
          </h:outputText>
        </p:column>
        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Produto" />
          </f:facet>
          <h:outputText value="#{order.product.name}" style="#{order.paymentDate eq null ? 'color: red;' : ''}"  />
        </p:column>
        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Fornecedor" />
          </f:facet>
          <h:outputText value="#{order.seller.name}" style="#{order.paymentDate eq null ? 'color: red;' : ''}"  />
        </p:column>
        <p:column style="text-align:right;">
          <f:facet name="header">
            <h:outputText value="Compra" />
          </f:facet>
          <h:outputText value="#{order.stringTotalBuyValue}" style="#{order.paymentDate eq null ? 'color: red;' : ''}"  />
        </p:column>
        <p:column style="text-align:right;">
          <f:facet name="header">
            <h:outputText value="Venda" />
          </f:facet>
          <h:outputText value="#{order.stringSellValue}" style="#{order.paymentDate eq null ? 'color: red;' : ''}"  />
        </p:column>
        <p:column style="text-align:right;">
          <f:facet name="header">
            <h:outputText value="Lucro" />
          </f:facet>
          <h:outputText value="#{order.stringTotalGainValue}" style="#{order.paymentDate eq null ? 'color: red;' : ''}"  />
        </p:column>
        <p:column style="text-align:center;">
          <h:graphicImage value="/images/status_comprado.gif" id="idSatusComprado" width="16" height="16" style="border: 0px;" title="produto encomendado" rendered="#{order.status.ordered}"/>
          <h:graphicImage value="/images/status_naoVendido.gif" id="idSatusNaoVendido" width="16" height="16" style="border: 0px;" title="produto não vendido" rendered="#{order.status.received}" />
          <h:graphicImage value="/images/status_vendidoAReceber.gif" id="idSatusVendidoAReceber" width="16" height="16" style="border: 0px;" title="produto vendido a receber" rendered="#{order.status.sold and order.sellStatus.unreceivePayment}" />
          <h:graphicImage value="/images/status_vendido.gif" id="idSatusVendido" width="16" height="16" style="border: 0px;" title="produto vendido" rendered="#{order.status.sold and order.sellStatus.receivePayment}" />
        </p:column>
        <p:column style="text-align:left;">
          <p:spacer width="5" />
          <h:commandLink id="lnkEdit" action="#{orderAction.prepareEditOrder}" >
            <h:graphicImage value="/images/action_edit.gif" width="16" height="16" style="border: 0px;" title="editar pedido" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
          </h:commandLink>
          <p:spacer width="5" />
          <p:commandLink id="lnkDelete" action="#{orderAction.prepareUpdateStatusOrder}" oncomplete="pnlEditOrder.show()" update="pnlEditOrder" >
            <h:graphicImage value="/images/action_delete.gif" width="16" height="16" style="border: 0px;" title="excluir pedido" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
            <f:setPropertyActionListener value="#{true}" target="#{orderAction.actionDelete}" />            
          </p:commandLink>
          <p:spacer width="5" rendered="#{order.status.ordered or order.status.received or (order.status.sold and order.sellStatus.unreceivePayment)}" /> 
          <p:commandLink id="lnkArriveItem" action="#{orderAction.prepareUpdateStatusOrder}" oncomplete="pnlEditOrder.show()" rendered="#{order.status.ordered}" update="pnlEditOrder" >
            <h:graphicImage value="/images/action_receberItem.gif" width="16" height="16" style="border: 0px;" title="receber produto" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
            <f:setPropertyActionListener value="#{true}" target="#{orderAction.actionArriveItem}" />            
          </p:commandLink>
          <p:commandLink id="lnkSell" action="#{orderAction.prepareUpdateStatusOrder}" oncomplete="pnlEditOrder.show()" rendered="#{order.status.received}" update="pnlEditOrder">
            <h:graphicImage value="/images/action_vender.gif" width="16" height="16" style="border: 0px;" title="vender produto" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
            <f:setPropertyActionListener value="#{true}" target="#{orderAction.actionSellItem}" />            
          </p:commandLink>
          <p:commandLink id="lnkReceivePayment" action="#{orderAction.prepareUpdateStatusOrder}" oncomplete="pnlEditOrder.show()" rendered="#{order.status.sold and order.sellStatus.unreceivePayment}" update="pnlEditOrder">
            <h:graphicImage value="/images/action_receberPagamento.gif" width="16" height="16" style="border: 0px;" title="receber pagamento" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
            <f:setPropertyActionListener value="#{true}" target="#{orderAction.actionReceivePaymentItem}" />            
          </p:commandLink>
          <p:spacer width="5" rendered="#{order.paymentStatus.unpayed}" />
          <p:commandLink id="lnkPay" action="#{orderAction.prepareUpdateStatusOrder}" oncomplete="pnlEditOrder.show()" rendered="#{order.paymentStatus.unpayed}" update="pnlEditOrder">
            <h:graphicImage value="/images/action_pagar.gif" width="16" height="16" style="border: 0px;" title="pagar pedido" />
            <f:setPropertyActionListener value="#{order}" target="#{orderAction.order}" />            
            <f:setPropertyActionListener value="#{true}" target="#{orderAction.actionPayItem}" />            
          </p:commandLink>
        </p:column>
      </p:dataTable>

      <p:spacer height="10" />
      <p:outputPanel id="pnlButons">
        <div align="right" id="divButons">
          <h:commandLink action="#{orderAction.prepareInsertOrder}" value="incluir novo pedido" />
        </div>
      </p:outputPanel>			
      <p:spacer height="10" />
      
      <ui:include src="panelEditOrder.xhtml"></ui:include>

      <ui:include src="panelDetailOrder.xhtml"></ui:include>

    </p:panel>
  </h:form>

  </ui:define>
</ui:composition>

